﻿
/*
 * Create table UDS_MailAttachment
 */
IF ( OBJECT_ID(N'dbo.UDS_MailAttachment', N'U') IS NULL )
BEGIN
    CREATE TABLE dbo.UDS_MailAttachment
    (
        FileId          int             NOT NULL IDENTITY(1,1),
        MailBodyID      int             NOT NULL,
        FileName        nvarchar(256)   COLLATE Chinese_PRC_CI_AS NOT NULL,
        FileSize        int             NOT NULL,
        FileAttribute   int             NOT NULL,
        VirtualPath     nvarchar(256)   COLLATE Chinese_PRC_CI_AS NOT NULL,
        TimeCreated     datetime        NOT NULL CONSTRAINT [DF_UDS_MailAttachment_TimeCreated] DEFAULT(getdate()),

        CONSTRAINT [PK_UDS_MailAttachment] PRIMARY KEY NONCLUSTERED ( FileId asc ),
        CONSTRAINT [FK_UDS_MailAttachment_MailBodyID] FOREIGN KEY (MailBodyID) REFERENCES dbo.UDS_MailBody(MailBodyID)
    );

    CREATE CLUSTERED INDEX [IX_UDS_MailAttachment_MailBodyID] ON dbo.UDS_MailAttachment (MailBodyID asc, FileId asc);
END
GO

ALTER TABLE dbo.UDS_MailAttachment ALTER COLUMN [VirtualPath] nvarchar(512) NOT NULL;
GO